package com.pgeneral.user.management.exception;


import com.pgeneral.user.management.config.ResultBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@ControllerAdvice
public class MyExceptionHandle {
    private static final Logger logger = LoggerFactory.getLogger(MyExceptionHandle.class);

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResultBean handle(Exception e) {
        if (e instanceof MyException) {
            MyException myException = (MyException) e;
            return ResultBean.Error(myException.getCode(), myException.getMessage());
        } else {
            logger.error("系统异常", e);
           return ResultBean.Error("1003", e.getMessage());
        }
    }
}

